package cn.terminus.biz.customer.customcontacts;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.customcontacts.dto.*;
import cn.terminus.data.customer.customcontacts.dao.CustomContactsDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (CustomContacts)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:18:41
 */
@Component
public class CustomContactsManager extends AbstractTerminusManager {
    @Autowired
    private CustomContactsDao customContactsDao;

    public Integer add(CustomContactsNewDto dto) throws DataAccessException {
        try {
            return customContactsDao.add(dto);
        } catch (Exception e) {
            logger.error("CustomContactsManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(CustomContactsEditDto dto) throws DataAccessException {
        try {
            return customContactsDao.update(dto);
        } catch (Exception e) {
            logger.error("CustomContactsManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomContactsResultDto> gets(CustomContactsGetsDto dto) throws DataAccessException {
        try {
            return customContactsDao.gets(dto);
        } catch (Exception e) {
            logger.error("CustomContactsManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomContactsResultDto> query(CustomContactsQueryDto dto) throws DataAccessException {
        try {
            return customContactsDao.query(dto);
        } catch (Exception e) {
            logger.error("CustomContactsManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(CustomContactsDeleteDto dto) throws DataAccessException {
        try {
            return customContactsDao.delete(dto);
        } catch (Exception e) {
            logger.error("CustomContactsManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<CustomContactsResultDto> page(CustomContactsQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<CustomContactsResultDto> result = (Page<CustomContactsResultDto>) customContactsDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), CustomContactsResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("CustomContactsManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer addMulti(List<CustomContactsNewDto> list) throws DataAccessException {
        try {
            return customContactsDao.addMulti(list);
        } catch (Exception e) {
            logger.error("CustomContactsManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<CustomContactsResultDto> queryByCustomIds(List<Long> customerIdList) throws DataAccessException {
        try {
            return customContactsDao.queryByCustomIds(customerIdList);
        } catch (Exception e) {
            logger.error("CustomContactsManager queryByCustomIds失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
